<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Initialize a cURL share handle</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.curl-share-close.html">curl_share_close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.curl-share-setopt.html">curl_share_setopt</a></div>
 <div class="up"><a href="ref.curl.html">cURL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.curl-share-init" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">curl_share_init</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0)</p><p class="refpurpose"><span class="refname">curl_share_init</span> &mdash; <span class="dc-title">Initialize a cURL share handle</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.curl-share-init-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>curl_share_init</strong></span>
    ( <span class="methodparam">void</span>
   )</div>

  <p class="para rdfs-comment">
   Allows to share data between cURL handles.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.curl-share-init-parameters">
  <h3 class="title">参数</h3>
  <p class="para">此函数没有参数。</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.curl-share-init-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns resource of type &quot;cURL Share Handle&quot;.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.curl-share-init-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4138">
    <p><strong>Example #1 <span class="function"><strong>curl_share_init()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     This example will create a cURL share handle, add two cURL handles to it,
     and then run them with cookie data sharing.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;cURL&nbsp;share&nbsp;handle&nbsp;and&nbsp;set&nbsp;it&nbsp;to&nbsp;share&nbsp;cookie&nbsp;data<br /></span><span style="color: #0000BB">$sh&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_share_init</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">curl_share_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$sh</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLSHOPT_SHARE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURL_LOCK_DATA_COOKIE</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Initialize&nbsp;the&nbsp;first&nbsp;cURL&nbsp;handle&nbsp;and&nbsp;assign&nbsp;the&nbsp;share&nbsp;handle&nbsp;to&nbsp;it<br /></span><span style="color: #0000BB">$ch1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://example.com/"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_SHARE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Execute&nbsp;the&nbsp;first&nbsp;cURL&nbsp;handle<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Initialize&nbsp;the&nbsp;second&nbsp;cURL&nbsp;handle&nbsp;and&nbsp;assign&nbsp;the&nbsp;share&nbsp;handle&nbsp;to&nbsp;it<br /></span><span style="color: #0000BB">$ch2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://php.net/"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_SHARE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Execute&nbsp;the&nbsp;second&nbsp;cURL&nbsp;handle<br />//&nbsp;&nbsp;all&nbsp;cookies&nbsp;from&nbsp;$ch1&nbsp;handle&nbsp;are&nbsp;shared&nbsp;with&nbsp;$ch2&nbsp;handle<br /></span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch2</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Close&nbsp;the&nbsp;cURL&nbsp;share&nbsp;handle<br /></span><span style="color: #0000BB">curl_share_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$sh</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Close&nbsp;the&nbsp;cURL&nbsp;handles<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.curl-share-init-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.curl-share-setopt.html" class="function" rel="rdfs-seeAlso">curl_share_setopt()</a> - Set an option for a cURL share handle.</span></li>
    <li class="member"><span class="function"><a href="function.curl-share-close.html" class="function" rel="rdfs-seeAlso">curl_share_close()</a> - Close a cURL share handle</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.curl-share-close.html">curl_share_close</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.curl-share-setopt.html">curl_share_setopt</a></div>
 <div class="up"><a href="ref.curl.html">cURL 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
